package com.systop.asset.service.impl;
import com.systop.asset.utils.TreeUtils;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.systop.asset.mapper.MaterialCategoryMapper;
import com.systop.asset.entity.MaterialCategory;
import com.systop.asset.service.IMaterialCategoryService;

/**
 * 耗材类别Service业务层处理
 * 
 * @author mc
 * @date 2025-06-26
 */
@Service
public class MaterialCategoryServiceImpl implements IMaterialCategoryService 
{
    @Autowired
    private MaterialCategoryMapper materialCategoryMapper;

    /**
     * 查询耗材类别
     * 
     * @param id 耗材类别主键
     * @return 耗材类别
     */
    @Override
    public MaterialCategory selectMaterialCategoryById(Long id)
    {
        return materialCategoryMapper.selectMaterialCategoryById(id);
    }

    /**
     * 查询耗材类别列表
     * 
     * @param materialCategory 耗材类别
     * @return 耗材类别
     */
    @Override
    public List<MaterialCategory> selectMaterialCategoryList(MaterialCategory materialCategory)
    {
        return materialCategoryMapper.selectMaterialCategoryList(materialCategory);
    }

    /**
     * 新增耗材类别
     * 
     * @param materialCategory 耗材类别
     * @return 结果
     */
    @Override
    public int insertMaterialCategory(MaterialCategory materialCategory)
    {
        if(materialCategoryMapper.selectMaterialCategoryByName(materialCategory.getName())!=null){
            return 0;
        }
        return materialCategoryMapper.insertMaterialCategory(materialCategory);
    }

    /**
     * 修改耗材类别
     * 
     * @param materialCategory 耗材类别
     * @return 结果
     */
    @Override
    public int updateMaterialCategory(MaterialCategory materialCategory)
    {
        MaterialCategory category = materialCategoryMapper.selectMaterialCategoryByName(materialCategory.getName());
        if(category!=null && category.getId()!=materialCategory.getId()){
            return 0;
        }
        return materialCategoryMapper.updateMaterialCategory(materialCategory);
    }

    /**
     * 批量删除耗材类别
     * 
     * @param ids 需要删除的耗材类别主键
     * @return 结果
     */
    @Override
    public int deleteMaterialCategoryByIds(Long[] ids)
    {
        return materialCategoryMapper.deleteMaterialCategoryByIds(ids);
    }

    /**
     * 删除耗材类别信息
     * 
     * @param id 耗材类别主键
     * @return 结果
     */
    @Override
    public int deleteMaterialCategoryById(Long id)
    {
        return materialCategoryMapper.deleteMaterialCategoryById(id);
    }
    /**
     * 返回耗材类别树形结构
     * @param materialCategory
     * @return
     */
    public List<MaterialCategory> getCategory(MaterialCategory materialCategory) {
        List<MaterialCategory> all=materialCategoryMapper.selectMaterialCategoryList(materialCategory);
        return TreeUtils.buildTree(all);
    }
}
